【TokyoWesterns CTF 5th 2019】Crypto--Real-Baby-Rsa

一道RSA的简单题

Description:

real-baby-rsa.7z


Solution:

下载完附件,打开看到这些代码
Image

然后我打算常规做,先去分解 n
结果发现怎样都分解不了,所以就转别的思路了

可以看到它的代码里是一个字一个字来加密的
我一开始尝试只加密T发现会生成一行数字,这就说明了我们可以通过暴力破解的方法来得到 flag

在 ASCII 码里,从 32 ~ 126 是可见字符,所以我们可以这么写来得到 flag

Image

exp如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import gmpy2

res = ''
n = gmpy2.mpz(36239973541558932215768154398027510542999295460598793991863043974317503405132258743580804101986195705838099875086956063357178601077684772324064096356684008573295186622116931603804539480260180369510754948354952843990891989516977978839158915835381010468654190434058825525303974958222956513586121683284362090515808508044283236502801777575604829177236616682941566165356433922623572630453807517714014758581695760621278985339321003215237271785789328502527807304614754314937458797885837846005142762002103727753034387997014140695908371141458803486809615038309524628617159265412467046813293232560959236865127539835290549091)
e = gmpy2.mpz(65537)

with open('./output', 'rb') as v1:
for c in v1:
if c != -1:
c = gmpy2.mpz(c)
for char in range(32, 127):
line = gmpy2.mpz(pow(char, e, n))
if line == c:
res += chr(char)
print res
else:
break

Flag:

1
TWCTF{padding_is_important}
文章目录
  1. 1. Description:
  2. 2. Solution:
  3. 3. Flag:
|